package cn.codeartist.springboot.example.config;

import cn.codeartist.springboot.component.rocketmq.proxy.RocketMQProducer;
import cn.codeartist.springboot.component.rocketmq.proxy.impl.DefaultRocketMQProducer;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Scope;

/**
 * jnai
 *
 * @author 艾江南
 * @date 2020/8/13
 */
@Lazy
@Configuration
public class RocketMQConfig {

    public static final String NAME_SRV_ADDR = "10.8.131.14:9876";

    @Bean
    public DefaultMQPushConsumer defaultMQPushConsumer() throws MQClientException {
        DefaultMQPushConsumer mqPushConsumer = new DefaultMQPushConsumer();
        mqPushConsumer.setNamesrvAddr(NAME_SRV_ADDR);
        mqPushConsumer.setConsumerGroup("CODEARTIST_CN_GROUP");
        mqPushConsumer.subscribe("CODEARTIST_CN_TOPIC", "CODEARTIST_CN_TAG");
        return mqPushConsumer;
    }

    @Bean
    @Scope(BeanDefinition.SCOPE_PROTOTYPE)
    public DefaultMQProducer defaultMqProducer() {
        return new DefaultMQProducer();
    }

    @Bean
    public RocketMQProducer rocketMqProducer() {
        DefaultRocketMQProducer producer = new DefaultRocketMQProducer();
        producer.setNameSrvAddr(NAME_SRV_ADDR);
        producer.setGroup("CODEARTIST_CN_GROUP");
        return producer;
    }
}
